<template>
  <div class="app-container">
    <el-card>
      <el-form :model="queryList" :inline="true" label-width="68px">
        <el-form-item label="换算系数">
          <el-input v-model="queryList.measrate" placeholder="请输入换算比例" clearable style="width: 150px" />
        </el-form-item>
        <el-form-item label="计量名称">
          <el-input v-model="queryList.pK_MEASDOC" placeholder="请输入计量单位" clearable style="width: 150px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-plus" @click="addDialog('add')">新增</el-button>
          <el-button type="primary" icon="el-icon-search" @click="filterDire">查询</el-button>
          <el-button type="danger" icon="el-icon-refresh" @click="clearAll">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card>
      <el-table :data="reducedUnitList" border height="605px">
        <el-table-column type="index" label="序号" align="center"> </el-table-column>
        <el-table-column prop="measrate" label="换算系数" align="center"></el-table-column>
        <el-table-column prop="nbuName" label="计量名称" align="center"></el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="addDialog('edit',scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="total, prev, pager, next, sizes,jumper" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" :current-page="queryList.pageNum" :page-size="queryList.pageSize"
        :page-sizes="[10, 20, 50,100]" :total="total">
      </el-pagination>
    </el-card>
    <reducedUnitAdd ref="reducedUnitAddRef" :visible.sync="visible" @addSuccess="addSuccess"/>
  </div>
</template>

<script>
  import reducedUnitAdd from "@/components/BasicInformation/reducedUnitAdd.vue"
  import {
    findNccBasicReducedUnitData,
  } from '@/api/basic/PersonnelInformation.js'
  export default {
    components: {
      reducedUnitAdd
    },
    data() {
      return {
        queryList: {
          pK_MEASDOC: '',
          measrate: '',
        },
        reducedUnitList: [], //el-table数据
        total: 0,
        visible: false,
      };
    },
    created() {
      this.getNccReducedUnitList();
    },
    methods: {
      getNccReducedUnitList() {
        findNccBasicReducedUnitData(this.queryList).then(response => {
          this.reducedUnitList = response.rows;
          this.total = response.total;
        });
      },
      //新增/修改后刷新列表
      addSuccess(){
        this.getNccReducedUnitList();
      },
      clearAll() {
        this.queryList = {
          pK_MEASDOC: "",
          measrate: "",
        };
        this.getNccReducedUnitList();
      },
      filterDire() {
        this.getNccReducedUnitList()
      },

      addDialog(type, row) {
        this.visible = true;
        this.$refs.reducedUnitAddRef.openDialog(type, row);
      },
      handleSizeChange(newsize) {
        this.queryList.pageNum = 1
        this.queryList.pageSize = newsize
        this.getNccReducedUnitList()
      },
      handleCurrentChange(newpage) {
        this.queryList.pageNum = newpage
        this.getNccReducedUnitList()
      },
    }
  };
</script>

<style scoped>
  .app-container {
    padding: 20px;
  }

  .el-card {
    margin-bottom: 20px;
  }

  .btn el-button {
    margin-bottom: 20px;
  }

  .el-pagination {
    float: right;
    margin: 20px;
  }
</style>
